package com.haiersen.sign.user.service;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import com.haiersen.sign.common.ErrorType;
import com.haiersen.sign.user.dao.UserMapper;
import com.haiersen.sign.user.entity.User;
import com.haiersen.sign.utils.JSONUtil;


@Service
public class UserService implements IUserService{
	
	@Autowired
	private UserMapper userMapper;
	@Override
	public Map<String, Object> updatelogin(String phone, String password) {
		User user=userMapper.selectUserByPhone(phone);
		if(user!=null&&DigestUtils.md5DigestAsHex(password.getBytes()).equals(user.getPassword())){
			Map<String , Object> map =new HashMap<String, Object>();
			map.put("userId", user.getUserId());
			return JSONUtil.getJSON(ErrorType.SUCCESS,map);
		}else{
			return JSONUtil.getJSON(ErrorType.LOGIN_ERROR);
		}
	}
}